package org.duanyu.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder chatClient) {
        this.chatClient = chatClient.build();
    }


    /**
     * 流式输出
     * @param message 传递来的消息
     * @return 返回结果集
     */
    @GetMapping("/chat")
    public Flux<String> chat(String message){
        return chatClient.prompt().user(message).stream().content();
    }
}
